package novel.storage.utils;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import novel.spider.NovelSiteEnum;
import novel.spider.entitys.Novel;
import novel.spider.impl.novel.DingDianNovelSpider2;
import novel.spider.interfaces.INovelSpider;
import novel.spider.util.NovelSpiderFactory;

public class MyThread extends Thread {
	protected List<String> list;
	protected SqlSessionFactory sqlSessionFactory;
	public MyThread(List<String> list,SqlSessionFactory sqlSessionFactory) {
		super();
		this.list=list;
		this.sqlSessionFactory=sqlSessionFactory;
	}
	@Override
	public void run() {
		for (String url : list) {
			INovelSpider spider = NovelSpiderFactory.getNovelSpider(url);
			List<Novel> novels = spider.getsNovel(url,3);
			for (Novel novel : novels) {
				if(novel.getType()==null)
					novel.setType("δ֪");
				novel.setAddTime(new Date());
				System.out.println(novel);
			}
			SqlSession session = sqlSessionFactory.openSession();
			session.insert("NovelMapper2.batchInsert", novels);
			session.commit();
			session.close();
			try {
				Thread.sleep(5000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
